<template>
    <view class="container">
        <image class="bg-image" src="/static/image.jpg" mode="aspectFill"></image>
        <view class="nav-bar">
            <view class="back-btn" @click="goBack">
                <image src="/static/return.png" mode="aspectFit" class="back-icon"/>
            </view>
            <text class="nav-title">文章详情</text>
        </view>
        
        <view class="content">
            <view class="card-body">
                <view class="article-header">
                    <text class="article-title">{{ article.article_title }}</text>
                    <text class="article-date">{{ formatDate(article.create_time) }}</text>
                </view>
                <text class="article-content">{{ article.article_content }}</text>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            article: {
                article_title: '',
                article_content: '',
                create_time: ''
            }
        }
    },
    onLoad(options) {
        // 从本地存储获取文章数据
        const article = uni.getStorageSync('currentArticle')
        console.log('获取到的文章数据：', article)
        
        if (article && article.article_content) {
            this.article = article
        } else {
            uni.showToast({
                title: '文章不存在',
                icon: 'none'
            })
            setTimeout(() => {
                uni.navigateBack()
            }, 1500)
        }
    },
    onUnload() {
        // 页面卸载时清除存储的文章数据
        uni.removeStorageSync('currentArticle')
    },
    methods: {
        goBack() {
            uni.navigateBack()
        },
        formatDate(dateStr) {
            if (!dateStr) return ''
            const date = new Date(dateStr)
            return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
        }
    }
}
</script>

<style>
.container {
    position: relative;
    min-height: 100vh;
}

.bg-image {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -1;
}

.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    padding: 40px 20px 20px;
    z-index: 100;
}

.back-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-icon {
    width: 24px;
    height: 24px;
}

.nav-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 500;
    color: #333;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}

.content {
    padding: 100px 20px 20px;
    min-height: 100vh;
}

.card-body {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 20px;
}

.article-header {
    margin-bottom: 20px;
}

.article-title {
    font-size: 20px;
    color: #333;
    font-weight: 500;
    margin-bottom: 8px;
    display: block;
}

.article-date {
    font-size: 12px;
    color: #666;
}

.article-content {
    font-size: 16px;
    color: #333;
    line-height: 1.6;
    white-space: pre-wrap;
}
</style> 